package com.ruoyi.project.lesson.banner.service.impl;

import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.common.service.ICommonService;
import com.ruoyi.project.lesson.banner.domain.LessonBanner;
import com.ruoyi.project.lesson.banner.mapper.LessonBannerMapper;
import com.ruoyi.project.lesson.banner.service.ILessonBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程bannerService业务层处理
 *
 * @author shixiangwen
 * @date 2020-12-07
 */
@Service
@DataSource(DataSourceType.KKFORMULA)
public class LessonBannerServiceImpl implements ILessonBannerService {

    @Autowired
    private LessonBannerMapper lessonBannerMapper;

    @Autowired
    private ICommonService commonService;

    /**
     * 查询课程banner
     *
     * @param id 课程bannerID
     * @return 课程banner
     */
    @Override
    public LessonBanner selectLessonBannerById(Long id) {
        return lessonBannerMapper.selectLessonBannerById(id);
    }

    /**
     * 查询课程banner列表
     *
     * @param lessonBanner 课程banner
     * @return 课程banner
     */
    @Override
    public List<LessonBanner> selectLessonBannerList(LessonBanner lessonBanner) {
        return lessonBannerMapper.selectLessonBannerList(lessonBanner);
    }

    /**
     * 新增课程banner
     *
     * @param lessonBanner 课程banner
     * @return 结果
     */
    @Override
    public int insertLessonBanner(LessonBanner lessonBanner) {
        return lessonBannerMapper.insertLessonBanner(lessonBanner);
    }

    /**
     * 修改课程banner
     *
     * @param lessonBanner 课程banner
     * @return 结果
     */
    @Override
    public int updateLessonBanner(LessonBanner lessonBanner) {
        return lessonBannerMapper.updateLessonBanner(lessonBanner);
    }

    /**
     * 删除课程banner对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteLessonBannerByIds(String ids) {
        return lessonBannerMapper.deleteLessonBannerByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除课程banner信息
     *
     * @param id 课程bannerID
     * @return 结果
     */
    @Override
    public int deleteLessonBannerById(Long id) {
        return lessonBannerMapper.deleteLessonBannerById(id);
    }

    @Override
    public int getMaxSort(Long id) {
        return commonService.selectTableColumnMaxValue("lesson_banner", "sort", " lesson_id = " + id) + 1;
    }
}
